using System.Web.Mvc;
using Coderoom.ScrumPlanner.Web;
using Xunit;

namespace Coderoom.ScrumPlanner.Tests.Unit.MvcTests
{
	public class CoderoomControllerTests
	{
		[Fact]
		public void View_returns_ViewResult_with_ViewName()
		{
			// arrange
			var controller = new TestController();

			// act
			var result = controller.Test();

			// assert
			Assert.IsType<ViewResult>(result);
			Assert.Equal("Test", ((ViewResult)result).ViewName);
		}

		[Fact]
		public void RedirectToAction_returns_RedirectToRouteResult_with_ViewName()
		{
			// arrange
			var controller = new TestController();

			// act
			var result = controller.Test2();

			// assert
			Assert.IsType<RedirectToRouteResult>(result);
			Assert.Equal("Test", ((RedirectToRouteResult)result).RouteValues["action"]);
		}

		[Fact]
		public void RedirectToAction_returns_RedirectToRouteResult_with_ViewName_and_RouteValues()
		{
			// arrange
			var controller = new TestController();

			// act
			var result = controller.Test3();

			// assert
			Assert.IsType<RedirectToRouteResult>(result);
			Assert.Equal("Test", ((RedirectToRouteResult)result).RouteValues["action"]);
			Assert.Equal("Title A", ((RedirectToRouteResult)result).RouteValues["title"]);
			Assert.Equal("slug-a", ((RedirectToRouteResult)result).RouteValues["slug"]);
		}

		#region Nested type: TestController

		private class TestController : CoderoomController
		{
			public ActionResult Test()
			{
				return View<TestController>(x => x.Test());
			}

			public ActionResult Test(string title, string slug)
			{
				return View<TestController>(x => x.Test());
			}

			public ActionResult Test2()
			{
				return RedirectToAction<TestController>(x => x.Test());
			}

			public ActionResult Test3()
			{
				return RedirectToAction<TestController>(x => x.Test("Title A", "slug-a"));
			}
		}

		#endregion
	}
}